home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2005 May / CyberMycha 05-2005 (Poland).bin / Immortal / cotndemo.exe / Data1.cab / combinewithshadowmapobjects. < prev    next >
Encoding:
Text File  |  2004-11-16  |  1.5 KB  |  44 lines

  1. // pixel shader to combine shadow map texture with model drawing to create shadows
  2. // used when drawing objects
  3.  
  4. ps_2_0                // version
  5. dcl t0.xyzw            // lookup object texel using this coordinate
  6. dcl t1.xyzw            // lookup texel on shadowmap using this coordinate
  7. dcl t2.x            // z from light point of view
  8. dcl v0.rgba            // input color
  9. dcl_2d s0            // object texture
  10. dcl_2d s1            // shadow map texture
  11.  
  12. // sample center point and three other nearby points and average the results
  13. def c0,     0.00087891,     0,                0,0        // point 2
  14. def c1,    -0.00043945,     0.00076116,    0,0        // point 3
  15. def c2,    -0.00043945,    -0.00076116,    0,0        // point 4
  16. def c3,     0.25,0.25,0.25,0.25        // factor
  17. // c16 defined by app:  1-shadowalpha, 1.0f, zbias, unused
  18.  
  19. add r1,t1,c0
  20. add r2,t1,c1
  21. add r3,t1,c2
  22.  
  23. texld r0, t1, s1    // get point 1 from shadow map
  24. texld r1, r1, s1    // get point 2 from shadow map
  25. texld r2, r2, s1    // get point 3 from shadow map
  26. texld r3, r3, s1    // get point 4 from shadow map
  27.  
  28. // add r4.r,t2.x,c16.z    // get z from vertex shader and add zbias 
  29. mov r4.r,t2.x // added z-bias in vertex shader
  30.  
  31. sub r0.r,r0.r,r4.r    
  32. sub r0.g,r1.r,r4.r
  33. sub r0.b,r2.r,r4.r
  34. sub r0.a,r3.r,r4.r
  35. cmp r5,r0,c16.y,c16.x  // r5 = results of the comparisons with all the points
  36. dp4 r6,r5,c3        // average the result
  37. mov r6.a,c16.y        // shadow alpha = 1.0 (ie shadow doesn't reduce alpha)
  38.  
  39. texld r0, t0, s0    // get the texel from the object texture
  40. mul r0,r0,v0        // combine with input color
  41. mul r0,r0,r6        // combine with shadow
  42. mov oC0,r0            // move resulting color to output
  43.  
  44.